﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace msBsc.WebUi.wMall.Public
{
    public partial class wfSearchDjackList : msBsc.Cls.BPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        public override void DoAction()
        {
            if (this.strAction == "init")
            {
                GetPagedDjackInfo();
                base.DoAction();
            }
        }

        private void GetPagedDjackInfo()
        {
            string pageIndex = this.GetParamHtValue("PageIndex");
            string sCondition = this.GetParamHtValue("scondition");
            int pagesize = 15;

            int ipageIndex;
            if (!int.TryParse(pageIndex, out ipageIndex))
            {
                ipageIndex = 1;
            }

            sCondition = string.IsNullOrEmpty(sCondition) ? string.Empty : "%" + sCondition + "%";

            using (msBsc.AppLogic.DataAlc.CBizCustomerRegister objCBizCustomerRegister = new AppLogic.DataAlc.CBizCustomerRegister())
            {
                Epm.AppLogic.Framework.CDbParmCollection parm = new Epm.AppLogic.Framework.CDbParmCollection();

                parm.Add(new Epm.AppLogic.Framework.CDbParm("ipageindex", System.Data.ParameterDirection.Input, Epm.AppLogic.Framework.EDbType.Integer, 8, ipageIndex));
                parm.Add(new Epm.AppLogic.Framework.CDbParm("ipagesize", System.Data.ParameterDirection.Input, Epm.AppLogic.Framework.EDbType.Integer, 8, pagesize));
                parm.Add(new Epm.AppLogic.Framework.CDbParm("keywords", System.Data.ParameterDirection.Input, Epm.AppLogic.Framework.EDbType.String, 1000, sCondition.Replace(",", "','").Replace("'", "")));

                System.Data.DataSet ds = objCBizCustomerRegister.DataObj.QueryBySP("DJK_SELECT_DJACK_LISTINFO_FOR_VIEW", parm);
                int pageCount = 1;
                int datarowCount = 0;

                if (ds.Tables[0].Rows.Count > 0)
                {
                    pageCount = (int)Math.Ceiling(Convert.ToInt32(ds.Tables[0].Rows[0]["DATACOUNT"]) / (double)pagesize);
                    datarowCount=Convert.ToInt32(ds.Tables[0].Rows[0]["DATACOUNT"]);
                }


                string strJson = msBsc.AppLogic.Cfg.HttpTools.GetJsonByTable(ds.Tables[0], "", "", 1, 20, "");
                this.ExecJScript(@"SetDjackList(" + strJson + "," + pageCount + "," + datarowCount + ");");

            }
        }
    }
}